﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Organizations;
using DualControl.Application.Organizations;
using DualControl.Application.Organizations.Dto;
using DualControl.Controllers;
using DualControl.RiskPoints;
using DualControl.RiskPoints.Dtos;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using X.PagedList;

namespace DualControl.Web.Mvc.Controllers
{
    public class RiskPointController : DualControlControllerBase
    {
      
        private readonly IRiskPointAppService _riskPointAppService ;   

        public RiskPointController(IRiskPointAppService riskPointAppService)
        {
            _riskPointAppService = riskPointAppService;
         
        }


        //public async Task<ActionResult> Index( GetRiskPointsInput input)
        public async Task<ActionResult> Index(int page)
        {

            int pagenumber = page < 1 ? 1 : page;

            GetRiskPointsInput input = new GetRiskPointsInput
            {
                SkipCount = (pagenumber - 1) * AppConsts.DefaultPageSize,
                MaxResultCount = AppConsts.DefaultPageSize
            };

            var result = await _riskPointAppService.GetPagedRiskPoints(input);



            var PageOfRiskPointListDto = new StaticPagedList<RiskPointListDto>(result.Items, pagenumber, AppConsts.DefaultPageSize, result.TotalCount);
            //将分页结果放入ViewBag供View使用
            ViewBag.PageOfRiskPointListDto = PageOfRiskPointListDto;
           
            //return View(riskPointList);
            return View();
        }      

        public async Task<ActionResult> EditRiskPointModal(int riskPointId)
        {
            var riskpoint = await _riskPointAppService.GetRiskPointForEdit(new NullableIdDto<int>(riskPointId));
          
            return View("_EditRiskPointModal", riskpoint.RiskPoint);
        }

        //返回风险评估列表信息
        public async Task<ActionResult> RiskEvaluation(int page)
        {
            int pagenumber = page < 1 ? 1 : page;
            GetRiskPointsInput input = new GetRiskPointsInput
            {
                SkipCount = (pagenumber - 1) * AppConsts.DefaultPageSize,
                MaxResultCount = AppConsts.DefaultPageSize
            };
            var result = await _riskPointAppService.GetPagedRiskPoints(input);
            var PageOfRiskPointListDto = new StaticPagedList<RiskPointListDto>(result.Items, pagenumber, AppConsts.DefaultPageSize, result.TotalCount);

            //将分页结果放入ViewBag供View使用
            ViewBag.PageOfRiskPointListDto = PageOfRiskPointListDto;

            return View();

        }

        //打开风险评估页面，进行评估或者进行修改
        //public async Task<ActionResult> EditRiskEvaluationModal(int riskPointId)
        //{
        //    var riskevaluation = await _riskPointAppService.GetRiskEvaluationForEdit(new NullableIdDto<int>(riskPointId));

        //    return View("_EditRiskEvaluationModal", riskevaluation);
        //}

    }
}